package com.pomr.model.equipmentstorage;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.pomr.model.menu.EquipmentCondition;
import com.pomr.model.menu.EquipmentStatus;
import com.pomr.model.synthesize.Equipment;
import com.pomr.model.synthesize.Manufacturer;
import com.pomr.model.sys.Agency;

/**
 * 库存记录明细
 * @author Administrator
 *
 */
@Entity
@Table(name="equipment_storage_detail",uniqueConstraints = {@UniqueConstraint(columnNames={"storage_id","sn"})})
public class EquipmentStorageDetail implements Serializable{

	public double getEarnestmoney() {
		return earnestmoney;
	}

	public void setEarnestmoney(double earnestmoney) {
		this.earnestmoney = earnestmoney;
	}

	public String getDid() {
		return did;
	}

	public void setDid(String did) {
		this.did = did;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getEspecification() {
		return especification;
	}

	public void setEspecification(String especification) {
		this.especification = especification;
	}

	public String getImei() {
		return imei;
	}

	public void setImei(String imei) {
		this.imei = imei;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public EquipmentCondition getEquipmentCon() {
		return equipmentCon;
	}

	public void setEquipmentCon(EquipmentCondition equipmentCon) {
		this.equipmentCon = equipmentCon;
	}

	public EquipmentStatus getEquipmentStatus() {
		return equipmentStatus;
	}

	public void setEquipmentStatus(EquipmentStatus equipmentStatus) {
		this.equipmentStatus = equipmentStatus;
	}

	public String getsN() {
		return sN;
	}

	public void setsN(String sN) {
		this.sN = sN;
	}

	public String getAgencyName() {
		return agencyName;
	}

	public void setAgencyName(String agencyName) {
		this.agencyName = agencyName;
	}

	public String getManufacturerName() {
		return manufacturerName;
	}

	public void setManufacturerName(String manufacturerName) {
		this.manufacturerName = manufacturerName;
	}

	public String getEquipmentName() {
		return equipmentName;
	}

	public void setEquipmentName(String equipmentName) {
		this.equipmentName = equipmentName;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public EquipmentStorage getEquipmentStorage() {
		return equipmentStorage;
	}

	public void setEquipmentStorage(EquipmentStorage equipmentStorage) {
		this.equipmentStorage = equipmentStorage;
	}

	

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")//AUTO 在mysql中需要指定使用本地策略生成主键值
	private Integer id;//主键
	
	
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="storage_id")
	private EquipmentStorage equipmentStorage;
	
	@Formula("(select a.name from agency a where a.id=(select es1.agency_id from equipment_storage es1 where es1.id=storage_id))")
	private String agencyName;//机构名称
	
	@Formula("(select m.name from manufacturer m where m.id=(select es2.manufacturer_id from equipment_storage es2 where es2.id=storage_id))")
	private String manufacturerName;//厂商名称
	
	@Formula("(select ep.specification from equipment ep where ep.id=(select es4.equipment_id from equipment_storage es4 where es4.id=storage_id))")
	private String especification;//设备型号
	
	@Formula("(select meq.name from menu_equipment meq where meq.id= (select e.kind_id from equipment e where e.id=(select es3.equipment_id from equipment_storage es3 where es3.id=storage_id)))")
	private String equipmentName;//设备名称
	
	@Column(name="sn", length=50)
	private String sN;//SN编码
	
	@Column(name="imei", length=30)
	private String imei;//移动设备识别码
	
	@Column(name="did", length=30)
	private String did;
	
	@Column(name="uid", length=30)
	private String uid;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="status",columnDefinition="int default 1")
	private EquipmentStatus equipmentStatus;//状态 默认值1空闲
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="econdition",columnDefinition="int default 1")
	private EquipmentCondition equipmentCon;//状态 默认值1正常
	
	@Formula("(select s.name from menu_equipment_status s where s.id=status)")
	private String status;//厂商名称
	
	@Formula("(select c.name from menu_equipment_condition c where c.id=econdition)")
	private String condition;//厂商名称
	
	@Formula("(select st.earnestmoney from equipment_storage st where st.id=storage_id)")
	private double earnestmoney;//定金
	
	@Column(name="remark", length=500)
	private String remark;//备注
	
	@Column(name="reason", length=500)
	private String reason;//清库原因
	

}
